#!/usr/bin/python3
import os
import os.path as path
import re
from sys import argv

def install():
    for po_file in os.listdir("i18n"):
        if po_file.endswith(".po"):
            print("[info] Install tranlation for %s" % po_file[:-3])
            os.system("msgfmt %s -o /usr/share/locale/%s/LC_MESSAGES/counts.mo" % 
                    (path.join("i18n", po_file), po_file[:-3]))

def new_lang():
    if len(argv) < 3:
        print("[err ] got %d, except 3" % (len(argv)))
    else:
        os.system("msginit -i i18n/counts.pot -l %s --no-translator -o i18n/%s.po" % (argv[2], argv[2]))
        print("[info] Create i18n/%s.po" % argv[2])

if __name__ == "__main__":
    if "install" in argv:
        install()
    elif "newlang" in argv:
        new_lang()
